const app = getApp()
Page({
  data: {
    addfrom: {}

  },
  onLoad: function (options) {

  },
  handleInput(e) {
    let nameKey = e.currentTarget.dataset.name
    let value = e.detail.value
    let newadd = this.data.addfrom
    newadd[nameKey] = value
    this.setData({
      addfrom: newadd
    })
  },
  submit() {
    let that = this
    // if(that.data.addfrom.phoneNum){
    if (!app.isValidPhoneNumber(that.data.addfrom.phoneNum)) {
      tt.showToast({
        title: "请输入正确手机号",
        icon: 'fail',
        mask: true,
        duration: 2000
      });
      return
    }
    app.getRequest('/applet/message/save','POST',that.data.addfrom).then(res=>{
      if(res.code==200){
        tt.showToast({
          title: '提交成功',
          icon: 'success',
          mask: true,
          duration: 2000,
          success: (res) => {
            this.setData({
              addfrom: {}
            })
          },
        });
        
      }else{
        tt.showToast({
          title: res.message,
          icon: 'fail',
          mask: true,
          duration: 2000
        });
      }
    })
  }
})